package utility;

import java.sql.CallableStatement;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.Date;

import clientMain.Login;

public class TimeServer {
	
	public static Timestamp getTimeServer(){
		Timestamp time;
        try{
        	Login.conn.setAutoCommit(false);
            CallableStatement cst = Login.conn.prepareCall("{call sp_getTime(?)}");
            //	Lay bien tra ve cua Procedure trong SQL
            cst.registerOutParameter(1, Types.TIME);      
            cst.executeUpdate();
            Login.conn.commit();
            time = cst.getTimestamp(1);
        }catch (Exception e) {
        	e.printStackTrace();
        	time = null;
        }
        return time;
	}
	
	public static Date toDate(Timestamp timestamp) {
	    long milliseconds = timestamp.getTime() + (timestamp.getNanos() / 1000000);
	    return new Date(milliseconds);
	}
	
}
